package com.neusoft.neu24g3.myhis2.demos.web;

import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;
import java.util.Date;

/**
 * GetRestController asdf
 *
 * @author Administrator
 * @version 2024/05/27 15:32
 **/
@RestController
@RequestMapping("post")
@CrossOrigin("*")
public class PostRestController {
    /**
     POST https://httpbin.org/post
     Content-Type: application/json

     {
     "age": 999,
     "name": "content",
     "hiredate": "2012-12-12 1:2:3"
     }
jackSON  String -- >  object
     @RequestBody ，此注解必须添加
     * @param user
     * @return
     */

    @PostMapping("f3")
    public  User  f3( @RequestBody User  user){
        return  user ;
    }


    @PostMapping("f2")
    public  Date f2(Date hiredate){
        return  hiredate;
    }

    /**
     ###
     POST http://localhost:8030/post/f1
     Content-Type: application/x-www-form-urlencoded

     age=999&name=content&hiredate=2024-05-27 1:2:3

     * @param user
     * @return
     */

    @PostMapping("f1")
    public  User f1( User user){
        return  user;
    }




//    //    RESTful
////    所有的参数都根据位置写在url路径中，PathVariable 可以获得任意请求（get，post等）路径中的数据
////      name =  dog, age =18, price = 5678
//// http://localhost:8030/get/f3/dog/18/5678
    @PostMapping("/f1/{name}/{age}/{price}")
    public String f1 (  @PathVariable("name") String  name ){
        System.out.println("name = " + name);
        return "f1";
    }

    @PostMapping("/login")
    public String login (   String  logid, String logpwd  ){
        System.out.println("logid = " + logid);
        System.out.println("logpwd = " + logpwd);
        return "login";
    }
    @PostMapping("/login/dog")
    public String logindog ( @RequestBody User  user ){
        System.out.println( user   );
        return "login";
    }
}

